﻿Ext.extend(demo.module,{
    init: function(){  
 	  var opt={ 
	  url:'inquiryquery'	  
	  };
	  var display={		
		   xtype:'combo',
			  store: new Ext.data.SimpleStore({
			  fields: ['v','t'],data: [['0','yes'],['1','no']]}					
			),
		   fieldLabel:'<font color=red>前台显示</font>',
		   name:'display',		   
		   valueField:'v',							
		   displayField: 't',							
		   typeAhead: true,
		   value:"1",				          
		   mode: 'local',
		   readOnly:true,
		   triggerAction: 'all',
		   forceSelection: true,
		   selectOnFocus:true
	  };  
	  var pageParams={start:0,limit:20};
	  opt.fields=[
	  {name:'id',text:'id',header:{hidden:true},ft:'hidden'},
	  {name:'isnew',text:'isnew',header:{hidden:true},ft:'hidden'},
	  {name:'name',text:'name',ft:{allowBlank:false},header:{renderer:function(v,m,r){
	     if(r.get("isnew")==0){return "<font color=red>NEW</font>&nbsp;&nbsp;"+v;}else{return v}
	  }}},	  
	  {name:'display',text:'显示',header:{width:50,renderer:function(v){return v=='0'?'yes':'no';}},ft:display},
	  {name:'addtime',text:'留言时间',ft:{xtype:'datefield',format:Ext.timeSaveFormat,menu:new DatetimeMenu()}
	    ,header:{width:120,renderer:function(v){return Ext.displayTime12(v);}}
	  },
	  {name:'country',text:'国家'},
	  {name:'company',text:'公司'},	 
	  {name:'tel',text:'联系电话'},
	  {name:'email',text:'电子邮件'},
	  {name:'address',text:'联系地址'},	  
	  {name:'messages',text:'留言内容',ft:{xtype:'textarea',height:80}},
	  {name:'reply',text:'回复内容',ft:{xtype:'textarea',height:80}}	    
	  ];
	  opt.windowConfig={width:650};	  
	  opt.gridConfig={};	
	  opt.gridConfig.tbar=[
	   {text:'添加',iconCls:'add',handler:function(x){
	     this.window.setTitle(x);
	     this.window.show();
	   }},
	   {
	     text:'修改',iconCls:'edit',handler:function(x)
	     {
	       this.window.setTitle(x);
	       this.edit();	 
	     }
	   },
	   {
	     text:'删除',iconCls:'delete',handler:function(x)
	     {	       
	       this.del(function(rs){
	         this.postJson({
	           url:'deleteinquiry',
	           params:{inquiry:{id:rs[0].get("id")}}
	         })
	       })
	     }	   
	   },
	   '->',
	   '-',
	   {
		   xtype:'searchfield',		   
		   paramName:'inquiry.name',
		   defaultParams:pageParams,		  
		   emptyText:'search asker',
		   listeners:{
		    usestore:function(){
		      this.store=g.ds;
		    }
		   }
		}		   
	  ];  
     
     opt.gridConfig.bbar={pageSize:pageParams.limit};     
	 var g=new Ext.fay.ui.CURDGrid(opt);
	 g.on("save",function(values){	    
	    var display=this.form.getForm().findField("display").getValue();
	    values.display=display;	  
	    if(this.isValid())
	    {
	      this.postJson({
	       url:'saveinquiry',
	       params:{inquiry:values}
	      })
	    }
	 });  
	 this.main.add(g.grid);
     this.main.doLayout();   
     g.ds.reload({params:pageParams});
   }
});